import {Entity} from "../../entity";
import {Alias, Column, Editor, Serialize} from "../../decorator";


//用户（U表）
export class User extends Entity{

    @Editor("String")
    @Alias("用户名称")
    @Serialize("name")
    public name: string = "";

    @Editor("Memo")
    @Alias("角色描述")
    @Serialize("description")
    public description: string = "";

    @Serialize("status")
    public status: number = 0;
    @Serialize("mobile")
    public mobile: string = "";
    @Serialize("email")
    public email: string = "";
    @Serialize("head")
    public head: string = "";
    @Serialize("sign")
    public sign: string = "";
    @Serialize("certificate")
    public certificate: string = "";

    @Serialize("token")
    public token: string = "";

    @Serialize("weixin")
    public weixin: any = null;

    @Serialize("authority")
    public authority: any = null;

    @Serialize("groups")
    public groups: any = [];

    public password: string;
    public repeat: string;


    constructor() {
        super();
    }

    fromJSON(obj) {
        super.fromJSON(obj);
    }

    clone(): any {
        const entity: any = super.clone();
        entity.groups = [...this.groups];
        return entity;
    }

    copy(entity: any) {
        super.copy(entity);
        this.groups = [...entity.groups];
    }

    register() {
        const obj = super.toJSON();
        obj.password = "000000";
        return obj;
    }

    reset() {
        const obj: any = {};
        obj._id = this._id;
        obj.password = this.password;
        return obj;
    }
}


